<!-- 合并撤销 -->
<template>
  <el-dialog
    v-if="mergeUndoDialog.visible"
    width="80%"
    top="7vh"
    title="合并撤销"
    custom-class="mergeUndoDialog"
    append-to-body
    :close-on-click-modal="false"
    :visible.sync="mergeUndoDialog.visible"
    @close="close()"
  >
    <avue-form ref="form" v-model="model" :option="option" @submit="handleSubmit"></avue-form>
    <avue-crud :option="mergeUndoDialog.option" :table-loading="mergeUndoDialog.loading" :data="mergeUndoDialog.data" v-model="mergeUndoDialog.form" ref="packBoxTableCrud">
    </avue-crud>

    <div slot="footer" class="dialog-footer">
      <el-button v-preventReClick @click="undoSubmit" type="primary" size="small" icon="el-icon-circle-plus-outline">撤 销</el-button>
      <el-button @click="cancel" size="small" icon="el-icon-circle-close">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { cancelMerge } from '@/api/warehouse/preMaterialList';

export default {
  name: 'mergeUndoDialog',
  components: {},
  props: {
    visible: {
      type: Boolean,
      default: false
    },
    undoData: {
      type: Array,
      default: () => []
    }
  },
  data() {
    return {
      form: {},
      option: {
        row: true,
        submitBtn: false,
        emptyBtn: false,
        labelWidth: 100,
        column: [
          {
            label: '撤销原因',
            prop: 'remark',
            type: 'textarea',
            span: 24,
            rules: [
              {
                required: true,
                message: '请输入撤销原因',
                trigger: 'blur'
              }
            ]
          }
        ]
      },
      mergeUndoDialog: {
        visible: false,
        loading: false,
        data: [],
        form: {},
        option: {
          tip: false,
          searchShow: true,
          searchSpan: 4,
          searchMenuSpan: 6,
          dialogClickModal: false,
          height: '200',
          border: true,
          addBtn: false,
          editBtn: false,
          viewBtn: false,
          cancelBtn: false,
          saveBtn: false,
          selection: false,
          menu: false,
          page: false,
          index: true,
          indexLabel: '序号',
          refreshBtn: false,
          expandBtn: false,
          columnBtn: false,
          column: [
            {
              label: '备料单号',
              prop: 'sheetNo'
            },
            {
              label: '关联领料单号',
              prop: 'pickSheetNoList'
            },
            {
              label: '工单号',
              prop: 'workOrderNoList'
            },
            {
              label: '生产订单号',
              prop: 'productionOrderNoList'
            },
            {
              label: '状态',
              prop: 'status',
              width: 80,
              type: 'select',
              dicData: [
                // { label: '已出库', value: 0 },
                // { label: '待备料', value: 1 },
                // { label: '出库中', value: 2 },
                // { label: '备料中', value: 3 },
                // { label: '待拣货', value: 4 },
                // { label: '拣货中', value: 5 },
                // { label: '已拣货', value: 6 }
                { label: '已发料', value: 0 },
                { label: '待备料', value: 1 },
                { label: '发料中', value: 2 },
                { label: '备料中', value: 3 },
                { label: '待拣货', value: 4 },
                { label: '拣货中', value: 5 },
                { label: '待发料', value: 6 }
              ]
            }
          ]
        }
      }
    };
  },
  watch: {
    visible: {
      handler(value) {
        this.mergeUndoDialog.visible = value;
      }
    },
    undoData: {
      handler(value) {
        this.mergeUndoDialog.data = structuredClone(value);
      }
    }
  },
  mounted() {},
  computed: {},
  methods: {
    undoSubmit() {
      this.$refs.form.submit();
    },
    cancel() {
      this.close();
    },
    handleSubmit(form, done) {
      cancelMerge({
        requestParams: {
          type: 'PREPARE_SHEET_REVOKE',
          idList: this.mergeUndoDialog.data.map((d) => d.id),
          remark: form.remark
        },
        actCode: 'pre-sheet-merge-revoke-act'
      })
        .then((res) => {
          done();
          this.$message.success('合并撤销成功');
          this.close();
        })
        .catch((err) => {});
    },
    close() {
      this.$refs.form.resetForm();
      this.mergeUndoDialog.visible = false;
      this.$emit('closeDialog');
    }
  }
};
</script>

<style lang="scss" scoped>
::v-deep .mergeUndoDialog {
  .avue-crud__menu {
    display: none;
  }
  .ruleRowForm {
    margin-bottom: 5px;
    .el-radio {
      margin-right: 10px;
    }
    .header-icon {
      margin-right: 10px;
    }
  }
}
</style>
